<template>
  <div class="home-singer">
    <h1>热门歌手</h1>
    <div class="wrapper" ref="wrapper">
      <!-- 滚动所需的容器 -->
      <ul class="content" ref="content">
        <li v-for="(item, index) in listData" :key="index" @click="selectItem(item)">
          <div class="cover">
            <van-image :src="item.singer_pic" radius="10" />
          </div>
          <span>{{ item.singer_name }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import { betterScrollHorizontal } from "../../common/betterScroll.js";
export default {
  data() {
    return {
      listData: [],
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      this.$request("get", "/singer/list").then((res) => {
        console.log(res);
        this.listData = res.data.list;
        betterScrollHorizontal(
          this,
          this.$refs.wrapper,
          this.$refs.content,
          this.listData.length,
          10
        );
      });
    },
    selectItem(item) {
      const id = item.singer_mid; //获取歌单的id
      this.$router.push({
        name: "singer",
        params: {
          id: id, //等同于id
        }
      }
      );
      //把点击歌手的信息保存下来,通过store方法
      // this.$store.commit('saveSinger',item)
      this.$store.dispatch('saveSingerAction',item)
    },
  },
};
</script>
<style  scoped>
.wrapper {
  width: 100%;
  overflow: hidden;
}

/* ul.content {
    width: calc(12 * 10rem);
  } */
ul.content li {
  width: 10rem;
  display: inline-block;
  vertical-align: top;
}

ul.content li * {
  margin: 0 0.1rem;
}

ul.content li>span {
  font-size: 0.8rem;
  color: red;
}
</style>
  